<template>
    <div>
        <BasicTable @register="registerTable">
            <template #action="{ record }">
            <TableAction
                :actions="[
                    {
                        label: '审核通过',
                        ifShow: record.status === 0,
                        popConfirm: {
                            title: '是否确认审核',
                            confirm: handleAudit.bind(null, record.id),
                        },
                    },
                    {
                        color: 'error',
                        label: '删除',
                        popConfirm: {
                            title: '是否确认删除',
                            confirm: handleDelete.bind(null, record.id),
                        },
                    },
                ]"
            />
            </template>
        </BasicTable>
    </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
    name: 'Comment',
});
</script>
<script lang="ts" setup>
import { ref } from 'vue';
import { BasicTable, useTable, TableAction, BasicColumn } from '@/components/Table';
import { Space } from 'ant-design-vue';
import { defHttp } from '@/utils/http/axios';
import { useMessage } from '@/hooks/web/useMessage';
import dayjs from 'dayjs';
const { createMessage } = useMessage();

const columns: BasicColumn[] = [
    {
        title: '订单编号',
        dataIndex:'sn',
        width: 120,
        fixed: 'left',
    },
    {
        title: '评价时间',
        dataIndex: 'date',
        width: 120,
    },
    {
        title: '姓名',
        dataIndex: 'name',
        width: 120,
    },
    {
        title: '手机号',
        dataIndex:'mobile',
        width: 120,
    },
    {
        title: '电站',
        dataIndex:'stationName',
        width: 120,
    },
    {
        title: '电桩',
        dataIndex: 'pileName',
        width: 120,
    },
    {
        title: '内容',
        dataIndex: 'content',
        width: 120,
        ellipsis: true,
    },
    {
        title: '状态',
        dataIndex:'status',
        width: 120,
        customRender: ({ record }) => {
            return record.status === 0? '待审核' : '审核通过'
        },
    },
];
const exportLoading = ref(false);
const sumData = ref(0)
// 5	2025-02-16 09:43:33.000	2025-02-16 09:43:37.000	278	168	1	1	16	1113	0	1
const [registerTable, { getForm, reload }] =
    useTable({
        api: '/admin/comment/list',
        useSearchForm: true,
        columns,
        showIndexColumn: true,
        indexColumnProps: {
            fixed: 'left',
        },
        formConfig: {
            labelWidth: 100,
            schemas: [
                {
                    component: 'Input',
                    label: '姓名或手机号',
                    field: 'name',
                    componentProps: {
                        allowClear: true,
                    },
                },
                {
                    component: 'ApiSelect',
                    label: '电站',
                    field: 'stationId',
                    componentProps: ({ formModel }) => {
                        return {
                            api: '/admin/main/stationList',
                            valueField: 'id',
                            labelField: 'name',
                            showSearch: true,
                            allowClear: true,
                            onChange: () => {
                                formModel.pileId = undefined;
                            }
                        }
                    },
                },
                {
                    component: 'ApiSelect',
                    label: '电桩',
                    field: 'pileId',
                    componentProps: ({ formModel }) => {
                        return {
                            api: '/admin/main/pileList',
                            params: {
                                stationId: formModel.stationId
                            },
                            valueField: 'id',
                            labelField: 'name',
                            showSearch: true,
                            allowClear: true,
                        }
                    },
                },
            ]
        },
        pagination: true,
        bordered: true,
        actionColumn: {
            width: 150,
            title: '操作',
            dataIndex: 'action',
            slots: { customRender: 'action' },
            fixed: 'right',
        },
    });
    const handleAudit = async (id: number) => {
        await defHttp.post({ url: `/admin/comment/pass/${id}`});
        createMessage.success('审核成功');
        reload();
    }
    const handleDelete = async (id: number) => {
        await defHttp.delete({ url: `/admin/comment/del/${id}` });
        createMessage.success('删除成功');
        reload();
    }
</script>
 